<?php

namespace app\web\controller;

use app\web\service\CouponService;

class CouponController extends CommonController
{
    public function initialize()
    {
//        $this->noCheckTokenAction = ["getOrderCouponList", "getUsableCouponList", "getSearchData"];
        parent::initialize();
    }

    // 获取订单页可使用的优惠券列表
    public function getOrderCouponList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(CouponService::class, [$this->returnData]);
        $this->returnData = $service->getListByFilter($this->app->request->userLoginData["id"], $this->params);
        return $this->return_result($this->returnData);
    }

    //获取用户的可使用优惠券列表
    public function getUsableCouponList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(CouponService::class, [$this->returnData]);
        $this->returnData = $service->getUsableCouponList($this->app->request->userLoginData["id"]); // 处理业务
        return $this->return_result($this->returnData);
    }

    //获取用户的已使用优惠券列表
    public function getUseCouponList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $id = $this->getTokenVar($this->params["token"], "id");
        $service = $this->app->invokeClass(CouponService::class, [$this->returnData]);
        $this->returnData = $service->getUseCouponList($id); // 处理业务
        return $this->return_result($this->returnData);
    }

    //获取用户的已过期优惠券列表
    public function getExpireCouponList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(CouponService::class, [$this->returnData]);
        $this->returnData = $service->getExpireCouponList($this->app->request->userLoginData["id"]); // 处理业务
        return $this->return_result($this->returnData);
    }

    //获取被推荐优惠卷
    public function getShareCoupon(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(CouponService::class, [$this->returnData]);
        $this->returnData = $service->getShareCoupon(); // 处理业务
        return $this->return_result($this->returnData);
    }

    //用户领取被推荐优惠券
    public function userReceiveShareCoupon(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(CouponService::class, [$this->returnData]);
        $this->returnData = $service->userReceiveShareCoupon($this->app->request->userLoginData["id"], $this->params); // 处理业务
        return $this->return_result($this->returnData);
    }
}
